package com.qckj.amz.utils.enums;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 通过国家代码获取亚马逊市场编号
 *
 * @author luchuan
 *
 * @since 2022/10/20
 *
 *
 */
public enum EnumMarketplaceIdByCountryCode {

    //国家二字码代码
    COUNTRYCODE_CN("CN", ""),
    COUNTRYCODE_UK("UK", "A1F83G8C2ARO7P"),
    COUNTRYCODE_US("US", "ATVPDKIKX0DER"),
    COUNTRYCODE_CA("CA", "A2EUQ1WTGCTBG2"),
    COUNTRYCODE_SG("SG", "A19VAU5U5O7RUS"),
    COUNTRYCODE_AU("AU", "A39IBJ37TRP1C6"),
    COUNTRYCODE_ES("ES", "A1RKKUPIHCS9HS"),
    COUNTRYCODE_MX("MX", "A1AM78C64UM0Y8"),
    COUNTRYCODE_FR("FR", "A13V1IB3VIYZZH"),
    COUNTRYCODE_DE("DE", "A1PA6795UKMFR9"),
    COUNTRYCODE_IT("IT", "APJ6JRA9NG5V4"),
    COUNTRYCODE_NL("NL", "A1805IZSGTT6HS"),
    COUNTRYCODE_SE("SE", "A2NODRKZP88ZB9"),
    COUNTRYCODE_PL("PL", "A1C3SOZRARQ6R3"),
    COUNTRYCODE_TR("TR", "A33AVAJ2PDY3EV"),
    COUNTRYCODE_IN("IN", "A21TJRUUN4KGV"),
    COUNTRYCODE_JP("JP", "A1VC38T7YXB528"),

    ;

    private String code;
    private String marketplaceId;

    EnumMarketplaceIdByCountryCode(String code, String marketplaceId) {
        this.code = code;
        this.marketplaceId = marketplaceId;
    }

    public String getCode() {
        return code;
    }

    public String getMarketplaceId() {
        return marketplaceId;
    }

    private static final Map<String, EnumMarketplaceIdByCountryCode> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.putAll(Stream.of(EnumMarketplaceIdByCountryCode.values()).collect(Collectors.toMap(EnumMarketplaceIdByCountryCode::getCode, e -> e)));
    }

    public static String getMarketplaceId(String code) {
        return Optional.of(ENUM_MAP.get(code)).map(EnumMarketplaceIdByCountryCode::getMarketplaceId).orElse("");
    }

}
